home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: warning: possibly incorrect assignment
- Date: 09 Jan 1996 16:30:50 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan9093050@qcd.lanl.gov>
- References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Bill Simpson's message of Tue, 9 Jan 1996 09:26:35 -0600
-
- --text follows this line--
- In article <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
- Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- <snip>
- I get the above warning when I compile code using the following
- function. It flags the **** line.
- <snip>
- **** while(fp=fopen(file_name,"r"))
- <snip>
- How can I write this code so the compiler does not issue this warning?
-
- Unfortunately compilers are allowed (by the standard) to issue
- as many more warnings than required as they please: it is a quality of
- implementation issue whether the warnings are useful. There is no
- general method of stopping a particular warning: but if an useless
- warning is very difficult to get rid off, I would instead get rid off
- the compiler.
-
- In this case, I think the warning is useful. The compiler is wondering
- whether you perhaps mistyped = for ==. (It would not have wondered so
- if it knew about the usage patterns of fopen, but few compilers today
- treat the library functions as special.) You could probably get rid
- off the warning by not doing the assignment in the test condition, but
- that is slightly inconvenient in this case.
-
- Most compilers shut up if the questionable assignment is inside a
- layer of parentheses, e.g. `while((fp=fopen(file_name,"r")))', or is a
- subexpression, e.g., `while((fp=fopen(file_name,"r")) != NULL)'. I
- often use the first form when dealing with such helpful compilers.
-
- Please don't suggest I just tell the compiler to shut up. In general
- the warnings are useful. I do not want to just ignore the warning either.
- I have the FAQ and haven't seen this discussed.
-
- If that is true, it should be included in the FAQ.
-
- (Any other improvements to above code segment welcomed)
-
- Haven't looked at the code, but remember that a file not being
- readable is no guarantee of its non-existence.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-